package com.ysq.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ysq.domain.BarcodeTemplate;
import com.ysq.service.IBarcodeTemplateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 标签模板Controller
 * 
 * @author ysq
 * @date 2025-09-02
 */
@RestController
@RequestMapping("/label/template")
public class BarcodeTemplateController extends BaseController
{
    @Autowired
    private IBarcodeTemplateService barcodeTemplateService;

    /**
     * 查询标签模板列表
     */
    @PreAuthorize("@ss.hasPermi('label:template:list')")
    @GetMapping("/list")
    public TableDataInfo list(BarcodeTemplate barcodeTemplate)
    {
        startPage();
        List<BarcodeTemplate> list = barcodeTemplateService.selectBarcodeTemplateList(barcodeTemplate);
        return getDataTable(list);
    }

    /**
     * 导出标签模板列表
     */
    @PreAuthorize("@ss.hasPermi('label:template:export')")
    @Log(title = "标签模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BarcodeTemplate barcodeTemplate)
    {
        List<BarcodeTemplate> list = barcodeTemplateService.selectBarcodeTemplateList(barcodeTemplate);
        ExcelUtil<BarcodeTemplate> util = new ExcelUtil<BarcodeTemplate>(BarcodeTemplate.class);
        util.exportExcel(response, list, "标签模板数据");
    }

    /**
     * 获取标签模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('label:template:query')")
    @GetMapping(value = "/{templateId}")
    public AjaxResult getInfo(@PathVariable("templateId") Long templateId)
    {
        return success(barcodeTemplateService.selectBarcodeTemplateByTemplateId(templateId));
    }

    /**
     * 新增标签模板
     */
    @PreAuthorize("@ss.hasPermi('label:template:add')")
    @Log(title = "标签模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BarcodeTemplate barcodeTemplate)
    {
        return toAjax(barcodeTemplateService.insertBarcodeTemplate(barcodeTemplate));
    }

    /**
     * 修改标签模板
     */
    @PreAuthorize("@ss.hasPermi('label:template:edit')")
    @Log(title = "标签模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BarcodeTemplate barcodeTemplate)
    {
        return toAjax(barcodeTemplateService.updateBarcodeTemplate(barcodeTemplate));
    }

    /**
     * 删除标签模板
     */
    @PreAuthorize("@ss.hasPermi('label:template:remove')")
    @Log(title = "标签模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{templateIds}")
    public AjaxResult remove(@PathVariable Long[] templateIds)
    {
        return toAjax(barcodeTemplateService.deleteBarcodeTemplateByTemplateIds(templateIds));
    }
}
